package com.bs.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bs.model.OrderItem;
import com.bs.service.IOrderItemService;
import com.bs.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 说明：
 *
 * @author 琪
 * @since 2025/5/7 20:29
 */
@RestController
@RequestMapping("orderOrderItem")
@Api(tags = "订单明细接口")
public class OrderItemController {

    @Autowired
    private IOrderItemService orderOrderItemService;

    @PostMapping("add")
    @ApiOperation(value = "添加订单明细")
    public RestResultVo<OrderItem> addOrderItem(@RequestBody OrderItem orderOrderItem) {
        orderOrderItemService.save(orderOrderItem);
        return RestResultVo.ok(orderOrderItem);
    }

    @GetMapping("delete")
    @ApiOperation(value = "删除订单明细")
    public RestResultVo<Boolean> deleteOrderItem(String id) {
        orderOrderItemService.removeById(id);
        return RestResultVo.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "修改订单明细")
    public RestResultVo<OrderItem> updateOrderItem(@RequestBody OrderItem orderOrderItem) {
        orderOrderItemService.updateById(orderOrderItem);
        return RestResultVo.ok(orderOrderItem);
    }

    @GetMapping("query")
    @ApiOperation(value = "查询订单明细")
    public RestResultVo<OrderItem> queryOrderItem(String id) {
        OrderItem orderOrderItem = orderOrderItemService.getById(id);
        return RestResultVo.ok(orderOrderItem);
    }

    @PostMapping("list")
    @ApiOperation(value = "查询订单明细列表")
    public RestResultVo<List<OrderItem>> listOrderItem(@RequestBody OrderItem orderOrderItem) {
        List<OrderItem> list = orderOrderItemService.list(new QueryWrapper<>(orderOrderItem));
        return RestResultVo.ok(list);
    }

}
